<cfcomponent 
	displayname="FormListener" 
	extends="MachII.framework.Listener" 
	output="false">

	<cffunction name="configure" access="public" output="false" returntype="void">
	</cffunction>
	
	<cffunction name="processInterestForm" access="public" output="false" returntype="void">
		<cfargument name="event" type="MachII.framework.Event" required="true" />
		
		<cfscript>
			var interestForm = arguments.event.getArg("interestForm");
			var errors = interestForm.validate();
			
			if (not ArrayIsEmpty(errors)) {
				arguments.event.setArg("errors", errors);
				redirectEvent("fail", "", true, arguments.event.getArgs());
			} else {
				try {
					GoogleWrite(interestForm);
					redirectEvent("success");
				} catch (any e) {
					var error = StructNew();
					error.message = e.message & " " & e.detail;
					ArrayAppend(errors, error);
					arguments.event.setArg("errors", error);
					redirectEvent("fail", "", true, arguments.event.getArgs());
				}
			}
		</cfscript>
		
	</cffunction>

</cfcomponent>